package com.ecube.sql;

import com.ecube.mqtt.MqttUtils;
import com.ecube.mqtt.mysql.Query;

import java.text.SimpleDateFormat;
import java.util.Date;

public class State3 {

    public static void main(String[] args) throws InterruptedException {
        int dcMeterElectAdd =34;
        int dcMeterElect = 0;

        while (true) {
            sendRealDataMQTT("HG", "1011111100100011", dcMeterElect);
            dcMeterElect = dcMeterElectAdd + dcMeterElect;
            Thread.sleep(1000*60);
        }
    }
    public static void sendRealDataMQTT(String env, String externalCode, int dcMeterElect) {
        String pubTopic = "100040002/" + externalCode + "/S2M/state";
        String version = Query.getVersion(env,externalCode);
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //仓位实时状态
        String content = " {\n" +
                "    \"dataBody\": {\n" +
                "        \"totalChgTime\": 5,\n" +
                "        \"MinTemp\": 20,\n" +
                "        \"soc\": 39,\n" +
                "        \"capacity\": 3446,\n" +
                "        \"voltDemand\": 450,\n" +
                "        \"remainderChgTime\": 89,\n" +
                "        \"chgVolt\": 500,\n" +
                "        \"currDemand\": 100,\n" +
                "        \"MinVoltNo\": -999,\n" +
                "        \"startTime\": \"2024-10-22 19:29:00\",\n" +
                "        \"vin\": \"YH838193718321930\",\n" +
                "        \"chgTime\": 20,\n" +
                "        \"chgOutputVolt\": 0,\n" +
                "        \"batType\": 3,\n" +
                "        \"batID\": \"131456678675342\",\n" +
                "        \"chgOutputCurr\": 0,\n" +
                "        \"chgCode\": \"1011111100100011\",\n" +
                "        \"MaxVoltNo\": 0,\n" +
                "        \"totalChgCount\": 16777215,\n" +
                "        \"gunCodeArray\": [\n" +
                "            2\n" +
                "        ],\n" +
                "        \"snno\": 5,\n" +
                "        \"MaxVolt\": 3,\n" +
                "        \"chgQty\": 20,\n" +
                "        \"MinTempNo\": 0,\n" +
                "        \"MaxTemp\": 31,\n" +
                "        \"MinVolt\": -999,\n" +
                "        \"productCode\": \"100040002\",\n" +
                "        \"dcMeterElect\": 17,\n" +
                "        \"chgMode\": 2,\n" +
                "        \"MaxTempNo\": 0,\n" +
                "        \"chgCurr\": 200\n" +
                "    },\n" +
                "    \"header\": {\n" +
                "        \"timeStamp\": \"" + dateFormat.format(date) + "\",\n" +
                "        \"reason\": 2,\n" +
                "        \"function\": \"chargeState\",\n" +
                "        \"index\": 5,\n" +
                "        \"version\": \"V1.0.8\"\n" +
                "    }\n" +
                "}";


        MqttUtils.sendMQTT(env, pubTopic, content);

    }
}
